#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	int n,t;
	cin>>t;
	while(t--)
	{
		int flg=0,minn,maxn;
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		minn=min(a[n],a[n-1]);
        maxn=max(a[n],a[n-1]);
		for(int i=n-2;i>=1;i--)
		{
			if(a[i]>minn||a[i]>maxn) 
			{
				flg=1;break;
			}
			if((n-i)%2==1) minn=a[i],maxn=a[i+1];
		}
		if(flg==1) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	
	return 0;
}

